﻿using DAL.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DAL.DBManagers
{
    public class PermissionsManager : BaseManager<Permission>
    {
        public PermissionsManager()
            : base()
        {
        }

        public override IEnumerable<Permission> GetAll()
        {
            return base.GetAll().Where(w => w.IsActive);
        }

        public List<PermissionHelper> GetUserPermission(Guid UserID)
        {
            var result = (_context as PortEntities).Permissions.Where(w => w.IsActive).Select(p => new PermissionHelper
            {
                PermissionID = p.PermissionID,
                PermissionName = p.NameGeo,
                IsChecked = p.UserPermissions.Any(a => a.IsActive && a.UserID == UserID)
            }).ToList();

            return result;
        }        
    }
}
